package com.eling.elcms.travel.webapp.controller;

import com.eling.elcms.core.dao.hibernate.search.SearchCondition;
import com.eling.elcms.core.webapp.controller.BaseFormController;
import com.eling.elcms.core.webapp.controller.Msg;
import com.eling.elcms.core.webapp.spring.ModelFilling;
import com.eling.elcms.travel.model.CarDispatchBill;
import com.eling.elcms.travel.service.ICarDispatchManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class CarDispatchController extends BaseFormController {

	@Autowired
	private ICarDispatchManager carDispatchManager;
	
	@RequestMapping("/api/cardispatch/search*")
	@ResponseBody
	public List<CarDispatchBill> sreach(@ModelAttribute SearchCondition sc,@ModelAttribute CarDispatchBill cond) {
		sc.setQueryCondition(cond);
		return carDispatchManager.search(sc); 
	}
	
	@RequestMapping("/api/cardispatch/query")
    @ResponseBody
    public List<CarDispatchBill> query(@ModelAttribute CarDispatchBill cond){
    	return carDispatchManager.queryAllRecord(cond); 
    }
	
	@RequestMapping("/api/cardispatch/save")
    @ResponseBody
    public CarDispatchBill save(@ModelAttribute@ModelFilling CarDispatchBill carDispatchBill) {
		return carDispatchManager.save(carDispatchBill);
    }
	
	@RequestMapping("/api/cardispatch/savecarbill")
    @ResponseBody
    public CarDispatchBill saveCarBill(@ModelAttribute@ModelFilling CarDispatchBill carDispatchBill) {
		return carDispatchManager.saveCarBill(carDispatchBill);
    }
	
	@RequestMapping("/api/cardispatch/{pkCarDispatch}/delete")
	@ResponseBody
	public Msg delete(@PathVariable Long pkCarDispatch) {
		carDispatchManager.remove(pkCarDispatch);
	    return new Msg("删除成功");
	}
	
	@RequestMapping("/api/cardispatch/searchcarbill")
	@ResponseBody
	public List<CarDispatchBill> sreachCarBill(@ModelAttribute SearchCondition sc,@ModelAttribute CarDispatchBill cond) {
		sc.setQueryCondition(cond);
		return carDispatchManager.sreachCarBill(sc); 
	}
}
